package com.ruoyi.community.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.community.domain.vo.ExerciseHistoryVo;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.community.domain.ExerciseHistory;
import com.ruoyi.community.service.IExerciseHistoryService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 活动记录Controller
 *
 * @author lj
 * @date 2022-02-22
 */
@RestController
@RequestMapping("/community/eserciseHistory")
public class ExerciseHistoryController extends BaseController
{
    @Autowired
    private IExerciseHistoryService exerciseHistoryService;

    /**
     * 查询活动记录列表
     */
    @PreAuthorize("@ss.hasPermi('community:eserciseHistory:list')")
    @GetMapping("/list")
    public TableDataInfo list(ExerciseHistoryVo exerciseHistory)
    {
        startPage();
        List<ExerciseHistoryVo> list = exerciseHistoryService.selectExerciseHistoryLists(exerciseHistory);
        return getDataTable(list);
    }

    /**
     * 导出活动记录列表
     */
    @PreAuthorize("@ss.hasPermi('community:eserciseHistory:export')")
    @Log(title = "活动记录", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ExerciseHistory exerciseHistory)
    {
        List<ExerciseHistory> list = exerciseHistoryService.selectExerciseHistoryList(exerciseHistory);
        ExcelUtil<ExerciseHistory> util = new ExcelUtil<ExerciseHistory>(ExerciseHistory.class);
        util.exportExcel(response, list, "活动记录数据");
    }

    /**
     * 获取活动记录详细信息
     */
    @PreAuthorize("@ss.hasPermi('community:eserciseHistory:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(exerciseHistoryService.selectExerciseHistoryById(id));
    }

    /**
     * 新增活动记录
     */
    @PreAuthorize("@ss.hasPermi('community:eserciseHistory:add')")
    @Log(title = "活动记录", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ExerciseHistory exerciseHistory)
    {
        return toAjax(exerciseHistoryService.insertExerciseHistory(exerciseHistory));
    }

    /**
     * 修改活动记录
     */
    @PreAuthorize("@ss.hasPermi('community:eserciseHistory:edit')")
    @Log(title = "活动记录", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ExerciseHistory exerciseHistory)
    {
        return toAjax(exerciseHistoryService.updateExerciseHistory(exerciseHistory));
    }

    /**
     * 删除活动记录
     */
    @PreAuthorize("@ss.hasPermi('community:eserciseHistory:remove')")
    @Log(title = "活动记录", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(exerciseHistoryService.updateExerciseHistoryByIds(ids));
    }
}
